﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.Globalization;
using System.Collections;

public partial class Subscriptions : System.Web.UI.Page
{
  
    protected void Page_Load(object sender, EventArgs e)
    {
        if (currentsubs.SelectedValue =="0")
            {
                addedit.Visible = false;
            }
        if (!Page.IsPostBack)
        {
           
            if (Request.QueryString["company"] != null)
            {
                addedit.Visible = true;
                SqlDataSource1.SelectParameters["company_id"].DefaultValue = Request.QueryString["company"];
                GridView1.DataBind();
                
                ViewState["company"] = Request.QueryString["company"];
                selects.Visible = false;
            

            }
        }
    }
    protected void currentsubs_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (currentsubs.SelectedValue != "0")
        {
            addedit.Visible = true;
            SqlDataSource1.SelectParameters["company_id"].DefaultValue = currentsubs.SelectedValue;
            GridView1.DataBind();
            ViewState["company"] = currentsubs.SelectedValue;
           
          
        }
        else
        {
            addedit.Visible = false;
            SqlDataSource1.SelectParameters["company_id"].DefaultValue = currentsubs.SelectedValue;
            GridView1.DataBind();
            ViewState["company"] = currentsubs.SelectedValue;
        }
    }

    protected override void InitializeCulture()
    {
        if (Session["CurrentCulture"] != null)
        {
            string lang = Session["CurrentCulture"].ToString();
            if (lang != null && lang != "")
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
                Thread.CurrentThread.CurrentCulture.DateTimeFormat = new CultureInfo("en-US", false).DateTimeFormat;
                // Thread.CurrentThread.CurrentCulture.Calendar=new  System.Globalization.GregorianCalendar();

            }
        }
        

    }

    protected void edit_Click(object sender, EventArgs e)
    { LinkButton lk=(LinkButton)sender;
        ViewState["aoe"] = lk.ToolTip;
        paidfees.Text= ((Label)lk.NamingContainer.FindControl("paidfees")).Text;
        DatePicker1.SelectedDateString = ((Label)lk.NamingContainer.FindControl("startofsub")).Text;
        DatePicker2.SelectedDateString = ((Label)lk.NamingContainer.FindControl("endofsub")).Text;
     // ScriptManager.RegisterStartupScript(this.up1, this.GetType(), "hj", "there();", true);
      Page.ClientScript.RegisterStartupScript(this.GetType(), "reports", "there();", true);
    }
    protected void save_Click(object sender, EventArgs e)
    {
        //////////////////////////////////////////////
        List<string> fields = new List<string>();
        ArrayList values = new ArrayList();
        List<string> types = new List<string>();
        ///////////////
        /////////////////
        fields.Add("company_id");
        types.Add("int");
        values.Add(ViewState["company"].ToString());
        /////////////////////////////////////////////////
        /////////////////
        fields.Add("paidfees");
        types.Add("string");
        values.Add(paidfees.Text);
        /////////////////////////////////////////////////
        fields.Add("startofsub");
        types.Add("datetime");
        values.Add(DatePicker1.SelectedDate);
        /////////////////////////////////////////////////
        fields.Add("endofsub");
        types.Add("datetime");
        values.Add(DatePicker2.SelectedDate);
        //////////////////////////////////
        if (ViewState["aoe"].ToString() == "0")
        {
            DB.INSERT("subscriptions", fields, types, values);
        }
        else
        {
            DB.UPDATE("subscriptions","int,id," + ViewState["aoe"].ToString(), fields, types, values);
         
        }
        ViewState["aoe"] = 0;
        GridView1.DataBind();

    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType ==DataControlRowType.DataRow )
        {
           
            string vv = ((Label)e.Row.FindControl("endofsub")).Text;
            DateTime  ff =DateTime.Parse(vv);
            LinkButton lk = (LinkButton)e.Row.FindControl("edits");
            if (ff > DateTime.Now)
            {
                addedit.Visible = false;
                lk.Enabled = true;
               
               // Page.ClientScript.RegisterStartupScript(this.GetType(), "reports", "there();", true);
            }
            else
            {

                lk.Text = this.GetLocalResourceObject("ended").ToString();
            }
        
      
        }
    }
    protected void newsub_Click(object sender, EventArgs e)
    {
        ViewState["aoe"] = 0;
        Page.ClientScript.RegisterStartupScript(this.GetType(), "reports", "there();", true);
    }
    protected void GridView1_RowCreated1(object sender, GridViewRowEventArgs e)
    {
        //if (e.Row.RowType == DataControlRowType.DataRow)
        //{
        //    e.Row.Attributes.Add("onmouseover", "this.Mystyle=this.style.backgroundColor;this.style.backgroundColor='#FFFFA8'");

        //    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.Mystyle");
        //}
    }
    
}
